#include <stdio.h>

int main(int argc, char *argv[])
{

    int n = 0, m = 0;

    while (scanf("%d %d", &n, &m) != EOF)
    {
        n = n + 1;
        int person[n], i = 0;
        //给每个人进行编号

        for (i = 1; i < n; i++)
        {
            person[i] = 1;
        }
        //开始数数
        int count = 1;
        for (i = 1; i <= n; i++)
        {
            if (i == n)
            {
                i = 1;
            }
            //淘汰
            if (person[i] > 0)
            {
                if (count == m)
                {
                    person[i] = 0;
                    count = 1;
                }
                else
                {
                    count++;
                }
            }
            //检查存活人数
            int live = 0;
            for (int l = 1; l < n; l++)
            {
                if (person[l] > 0)
                {
                    live++;
                }
            }
            //宣布胜者
            if (live == 1)
            {
                for (int w = 1; w < n; w++)
                {
                    if (person[w] > 0)
                    {
                        printf("%d\n", w);
                        break;
                    }
                }
                break;
            }
        }
    }

    return 0;
}